package com.sugar.psych.assessment.module.business.controller.admin.usertreeholeclock;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.success;

import com.sugar.psych.assessment.framework.excel.core.util.ExcelUtils;

import com.sugar.psych.assessment.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.psych.assessment.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.psych.assessment.module.business.controller.admin.usertreeholeclock.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.usertreeholeclock.UserTreeHoleClockDO;
import com.sugar.psych.assessment.module.business.service.usertreeholeclock.UserTreeHoleClockService;

@Tag(name = "管理后台 - 树洞打卡")
@RestController
@RequestMapping("/business/user-tree-hole-clock")
@Validated
public class UserTreeHoleClockController {

    @Resource
    private UserTreeHoleClockService userTreeHoleClockService;

    @PostMapping("/create")
    @Operation(summary = "创建树洞打卡")
    @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:create')")
    public CommonResult<Long> createUserTreeHoleClock(@Valid @RequestBody UserTreeHoleClockSaveReqVO createReqVO) {
        return success(userTreeHoleClockService.createUserTreeHoleClock(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新树洞打卡")
    @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:update')")
    public CommonResult<Boolean> updateUserTreeHoleClock(@Valid @RequestBody UserTreeHoleClockSaveReqVO updateReqVO) {
        userTreeHoleClockService.updateUserTreeHoleClock(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除树洞打卡")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:delete')")
    public CommonResult<Boolean> deleteUserTreeHoleClock(@RequestParam("id") Long id) {
        userTreeHoleClockService.deleteUserTreeHoleClock(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除树洞打卡")
                @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:delete')")
    public CommonResult<Boolean> deleteUserTreeHoleClockList(@RequestParam("ids") List<Long> ids) {
        userTreeHoleClockService.deleteUserTreeHoleClockListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得树洞打卡")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:query')")
    public CommonResult<UserTreeHoleClockRespVO> getUserTreeHoleClock(@RequestParam("id") Long id) {
        UserTreeHoleClockDO userTreeHoleClock = userTreeHoleClockService.getUserTreeHoleClock(id);
        return success(BeanUtils.toBean(userTreeHoleClock, UserTreeHoleClockRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得树洞打卡分页")
    @PreAuthorize("@ss.hasPermission('business:user-tree-hole-clock:query')")
    public CommonResult<PageResult<UserTreeHoleClockRespVO>> getUserTreeHoleClockPage(@Valid UserTreeHoleClockPageReqVO pageReqVO) {
        return success(userTreeHoleClockService.getUserTreeHoleClockPage(pageReqVO));
    }

}